// GLCD.h
#ifndef	GLCD_H
#define	GLCD_H

// Standar library includes
#include	<stdlib.h>	// Only for abs function.
#include	<stdint.h>

#include	"KS0108.h"
#include	"Pin.h"
#include	"Bus.h"
#include	"Font.h"
#include	"BMP.h"


#define		GLCD_COLOR_WHITE	0
#define		GLCD_COLOR_BLACK	1
#define		GLCD_NO_FILL		0
#define 	GLCD_FILL			1
#define		GLCD_WIDTH			128
#define		GLCD_HEIGHT			64
#define		GLCD_NO_INVERT		0
#define		GLCD_INVERT			1


#define		getOffset( x, y )	((x) + (int16_t)((y)/8)*this->width)
#define		getKS0108( x )		((x) >= (this->width/2))

struct sGLCD{
	uint8_t width, height;
	uint8_t *pBuffer;
	struct sKS0108 KS0108[2];
};

struct sPoint{
	int16_t x, y;
};

struct sLine{
	int16_t x0, y0, x1, y1;
};

struct sCircle{
	uint16_t x, y, r;
};

struct sRect{
	int16_t x, y, w, h;
};


uint8_t GLCDOpen( struct sGLCD *this );
uint8_t GLCDClose( struct sGLCD *this );

void GLCDPixel( struct sGLCD *this, int16_t x, int16_t y, uint8_t color );
uint8_t GLCDGetPixel( struct sGLCD *this, int16_t x, int16_t y );
void GLCDLine( struct sGLCD *this, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color);
void GLCDRect( struct sGLCD *this, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t fill, uint8_t color);
void GLCDCircle( struct sGLCD *this, int16_t x, int16_t y, uint8_t r, uint8_t fill, uint8_t color );

void GLCDText( struct sGLCD *this, const struct sFont *pFont, char *str, int16_t x, int16_t y, uint8_t invert, uint8_t fill, uint8_t color);
uint16_t GLCDTextWidth( const struct sFont *pFont, char *str );

void GLCDDrawBMP( struct sGLCD *this, const struct sBMP *pBMP, int16_t x, int16_t y );

void GLCDClear( struct sGLCD *this );
void GLCDRefresh( struct sGLCD *this );

void GLCDsPixel( struct sGLCD *this, struct sPoint p, uint8_t color );
uint8_t GLCDsGetPixel( struct sGLCD *this, struct sPoint p );
void GLCDsLine( struct sGLCD *this, struct sLine l, uint8_t color);
void GLCDsRect( struct sGLCD *this, struct sRect r, uint8_t fill, uint8_t color);
void GLCDsCircle( struct sGLCD *this, struct sPoint p, uint8_t r, uint8_t fill, uint8_t color );

void GLCDsText( struct sGLCD *this, const struct sFont *pFont, char *str, struct sPoint p, uint8_t invert, uint8_t fill, uint8_t color);
void GLCDsDrawBMP( struct sGLCD *this, const struct sBMP *pBMP, struct sPoint p );


#endif	// GLCD_H
